package com.graduationproject.examonline.student.controller;

import com.graduationproject.examonline.student.service.StudentService;
import com.graduationproject.examonline.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("api/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping("/login")
    public Result login(String stu_id, String stu_password) {
        return studentService.login(stu_id, stu_password);
    }

    @PostMapping("/updatePassword")
    public Result updatePassword(@RequestBody Map<String, Object> params) {
        String stu_id = (String) params.get("stu_id");
        String pre_password = (String) params.get("pre_password");
        String next_password = (String) params.get("next_password");
        return studentService.updatePassword(stu_id, pre_password, next_password);
    }

    @PostMapping("/updateName")
    public Result updateName(@RequestBody Map<String, Object> params) {
        String stu_id = (String) params.get("stu_id");
        String stu_name = (String) params.get("stu_name");
        return studentService.updateName(stu_id, stu_name);
    }

    @GetMapping("/getAllUserInfo")
    public Result getAllUserInfo() {
        return studentService.getAllUserInfo();
    }

    @GetMapping("/getUserInfo")
    public Result getUserInfo(String stu_id) {
        return studentService.getUserInfo(stu_id);
    }

    @PostMapping("/updateStudentById")
    public Result updateStudentById(@RequestBody Map<String, Object> p) {
        return studentService.updateById(p);
    }

    @PostMapping("/insertStudet")
    public Result insertStudet(@RequestBody Map<String, Object> p) {
        return studentService.insertStudet(p);
    }

}
